import pymysql

# 删除数据
try:
    con = pymysql.connect(host="localhost", user="root", password="rootroot", db="blog")
    print(con)
    cursor = con.cursor()

    # 删除sql
    sql = 'delete from student where age < 22'

    # 执行sql
    cursor.execute(sql)
    # 获取查询结果
    con.commit()

    print("删除成功")
except Exception as e:
    print(e)
    con.rollback()
    print("删除失败")
finally:
    # 关闭数据库连接
    con.close()
